package core;

import gui.Resizer;
import gui.TopPanel;

import java.util.ArrayList;
import java.util.Collection;

import javax.swing.JApplet;
import javax.swing.JComponent;
import javax.swing.SwingUtilities;

import model.Model;

public class MainApplet extends JApplet{

	private static final long serialVersionUID = 1L;
	
	Model model;
	TopPanel panel;
	
	@Override
	public void init(){
		model = new Model();
		try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    createGUI();
                }
            });
        } catch (Exception e) { 
            System.err.println("createGUI didn't complete successfully");
            e.printStackTrace();
        }
        
	}
	
	@Override
	public void start(){
		/*for(int i=0; i<55; i++){
		model.update();
		System.out.println(model.getStatusString());
		panel.addText(model.getStatusString());
		}
		model.addNewNode(100, 100, false, false, 2);
		for(int i=0; i<2; i++){
			model.update();
			System.out.println(model.getStatusString());
			panel.addText(model.getStatusString());
		}
		model.removeNode(0);
		for(int i=0; i<5; i++){
			model.update();
			System.out.println(model.getStatusString());
			panel.addText(model.getStatusString());
		}
		*/
	}
	
	@Override
	public void stop(){
		
	}
	
	@Override
	public void destroy(){
		
	}
	
	private void createGUI(){
		Collection<JComponent> components = new ArrayList<JComponent>();
		TopPanel newContentPane = new TopPanel(model);
        newContentPane.setOpaque(true); 
        setContentPane(newContentPane);
        panel = newContentPane;
        
        components.add(newContentPane);
        
        this.addComponentListener(new Resizer(components));
        
	}

}
